package com.allwees.bs.c.module.payment.req;

import com.allwees.bs.core.modelbase.constant.ErrorMessage;
import com.allwees.bs.core.modelbase.req.SignedReq;
import com.allwees.bs.core.modelbase.validate.ValidateItem;
import com.allwees.core.common.constant.EPlatform;
import com.allwees.core.common.util.json.JsonUtil;
import com.allwees.support.payment.encryptor.CreditCardEncryptor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;

@Data
@EqualsAndHashCode(callSuper = true)
//@ApiModel(value = "信用卡支付vo")
public class PaymentPaypalCreditCardReq extends SignedReq {

    @NotNull(message = ErrorMessage.PARAM_NOT_NULL)
    private String orderUuid;

//    @ApiModelProperty(value = "调用该接口的平台，不区分大小写", example = "IOS,ANDROID,H5", required = true)
    private EPlatform platform;

    private String creditCard;

    @Override
    public ValidateItem[] getValidateItems() {
        return ArrayUtils.addAll(super.getValidateItems(),
                new ValidateItem(StringUtils.isBlank(orderUuid), "orderUuid can not be empty"),
                new ValidateItem(StringUtils.isBlank(creditCard), "creditCard can not be empty"),
                new ValidateItem(platform == null, "platform can not be a null"));
    }

    @Override
    protected Object[] signValues() {
        return new Object[]{orderUuid, creditCard, platform.name(), getTime().getTime()};
    }

    @Override
	protected String signSeparator(){
        return platform.isApp() ? "_APP_" : "_WEB_";
    }

    public PaymentCreditCardReq getCreditCardInfo() {
        PaymentCreditCardReq creditCardReq = JsonUtil.fromJson(CreditCardEncryptor.decrypt(getCreditCard(),
        		CreditCardEncryptor.CARD_SEED + signSeparator()), PaymentCreditCardReq.class);
        creditCardReq.validate();
        return creditCardReq;
    }
}
